package tenantchannellogic

import (
	"context"

	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/tenant/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BankInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBankInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BankInfoLogic {
	return &BankInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BankInfoLogic) BankInfo(in *rpc.BankInfoRequest) (*rpc.BankInfoResponse, error) {
	var CommonResp rpc.CommonResp

	bankModel := model.NewTenantChannelBankModel(l.ctx, l.svcCtx.Db)
	bank, err := bankModel.GetBankById(in.Id)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Bank not found"
		return &rpc.BankInfoResponse{
			CommonResp: &CommonResp,
		}, err
	}

	CommonResp.Message = "Success"
	return &rpc.BankInfoResponse{
		Id:           bank.ID,
		CreatedAt:    bank.CreatedAt,
		UpdatedAt:    bank.UpdatedAt,
		Code:         bank.Code,
		Phone:        bank.Phone,
		MinAmount:    bank.MinAmount,
		MaxAmount:    bank.MaxAmount,
		DailyTimes:   bank.DailyTimes,
		DailyAmount:  bank.DailyAmount,
		RemainTimes:  bank.RemainTimes,
		RemainAmount: bank.RemainAmount,
		VisionLevel:  bank.VisionLevel,
		IsDisplay:    bank.IsDisplay,
		CardNumber:   bank.CardNumber,
		BankNickname: bank.BankNickname,
		BankName:     bank.BankName,
		IfscCode:     bank.IfscCode,
		Email:        bank.Email,
		Province:     bank.Province,
		City:         bank.City,
		BranchBank:   bank.BranchBank,
		IsLimit:      bank.IsLimit,
		CardHolder:   bank.CardHolder,
		Sort:         bank.Sort,
		CommonResp:   &CommonResp,
	}, nil
}
